package #(javaGenTool.controllerPackagePath);


import #(javaGenTool.boPackagePath).#(javaGenTool.boClassName);
import #(javaGenTool.qoPackagePath).#(javaGenTool.qoClassName);
import #(javaGenTool.voPackagePath).#(javaGenTool.voClassName);
import #(javaGenTool.servicePackagePath).#(javaGenTool.serviceClassName);

import com.mybatisflex.core.paginate.Page;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.web.bind.annotation.*;
import lombok.RequiredArgsConstructor;

import java.util.List;

/**
 * #(table.getComment()) 控制层。
 *
  * @author #(javadocConfig.getAuthor())
  * @since #(javadocConfig.getSince())
 */
@Tag(name = "#(table.getComment())接口")
@RequiredArgsConstructor
@RestController
@RequestMapping("#(table.buildEntityClassName())")
public class #(javaGenTool.controllerClassName)  {

    private final #(javaGenTool.serviceClassName) #(javaGenTool.lowerServiceClassName);

    /**
     * 新增
     *
     * @param #(javaGenTool.lowerBoClassName) 表单
     * @return {@code true} 添加成功，{@code false} 添加失败
     */
    @PostMapping("add")
    @Operation(description="新增")
    public boolean add(@RequestBody #(javaGenTool.boClassName) #(javaGenTool.lowerBoClassName)) {
        return #(javaGenTool.lowerServiceClassName).add(#(javaGenTool.lowerBoClassName));
    }

    /**
     * 根据主键删除
     *
     * @param id 主键
     * @return {@code true} 删除成功，{@code false} 删除失败
     */
    @DeleteMapping("remove/{id}")
    @Operation(description="根据主键删除")
    public boolean remove(@PathVariable Long id) {
        return #(javaGenTool.lowerServiceClassName).remove(id);
    }

    /**
     * 根据主键更新
     *
     * @param #(javaGenTool.lowerBoClassName) 表单
     * @return {@code true} 更新成功，{@code false} 更新失败
     */
    @PutMapping("update")
    @Operation(description="根据主键更新")
    public boolean update(@RequestBody #(javaGenTool.boClassName) #(javaGenTool.lowerBoClassName)) {
        return #(javaGenTool.lowerServiceClassName).update(#(javaGenTool.lowerBoClassName));
    }

    /**
     * 条件查询所有数据
     *
     * @return 条件查询所有数据
     */
    @GetMapping("list")
    @Operation(description="条件查询所有数据")
    public List<#(javaGenTool.voClassName)> list(#(javaGenTool.qoClassName) #(javaGenTool.lowerQoClassName)) {
        return #(javaGenTool.lowerServiceClassName).list(#(javaGenTool.lowerQoClassName));
    }

    /**
     * 根据主键获取详细信息。
     *
     * @param id 主键
     * @return 详情
     */
    @GetMapping("getInfo/{id}")
    @Operation(description="根据主键获取")
    public #(javaGenTool.voClassName) getInfo(@PathVariable Long id) {
        return #(javaGenTool.lowerServiceClassName).getInfo(id);
    }

    /**
     * 分页查询
     *
     * @param page 分页对象
     * @return 分页对象
     */
    @GetMapping("page")
    @Operation(description="分页查询")
    public Page<#(javaGenTool.voClassName)> page(#(javaGenTool.qoClassName) page) {
        return #(javaGenTool.lowerServiceClassName).page(page);
    }

}
